import java.util.Observable;

public class ListCoursesMandatory extends Communication {

	public ListCoursesMandatory( Integer registrationNumber, String componentName ) {
		super(registrationNumber, componentName);
	}
	
	public void update(Observable thing, Object notificationNumber) {
		Menus menu = new Menus();
		Displays display = new Displays();
		Student myStudent = new Student();
		boolean done = false;
		boolean takenDone = false;
		boolean found = false;
		boolean first = true;
		Course TakenCourse, MandatoryCourse;
		
		if (registrationNumber.compareTo((Integer)notificationNumber) == 0)
		{
			addToReceiverList("ListStudentsComponent");
			signalReceivers("ListStudentsComponent");
			myStudent = menu.pickStudent(CommonData.theListOfStudents.listOfStudents);
			
			
			if (myStudent != null)
			{
				CourseList cl = myStudent.getCoursesTakenList();
				CourseList mcl = CommonData.MandatoryCourses;
				
				cl.goToFrontOfList();
				mcl.goToFrontOfList();
				
				while(!done)
				{
					MandatoryCourse = mcl.getNextCourse();
					found = false;
					if (MandatoryCourse == null)
					{
						done = true;
					}
					else
					{
						cl.goToFrontOfList();
						takenDone = false;
						while(!takenDone)
						{
							TakenCourse = cl.getNextCourse();
							
							if (TakenCourse == null)
							{
								takenDone = true;
							}
							else if(MandatoryCourse.getCourseID().equalsIgnoreCase(TakenCourse.getCourseID()))
							{
								found = true;
							}
						}
						
						if(!found)
						{
							if(first)
							{
								display.displayMandatoryCoursesTitle(myStudent);
								first = false;
							}
							display.displayCourseWithoutGroup(MandatoryCourse);
						}
					}
				}
			}
			else
			{
				System.out.println("\n\n *** Student not found ***");
			}
		}
		removeFromReceiverList("ListStudentsComponent");
	}
}
